<template>
  <div class="guide-container">
    <!-- 欢迎引导页 -->
    <WelcomeGuide v-if="currentStep === 'welcome'" @next="nextStep" @skip="skipGuide" />
    
    <!-- 功能介绍引导页 -->
    <FeatureGuide v-if="currentStep === 'features'" @next="nextStep" @back="previousStep" @finish="finishGuide" />
    <!-- 权限说明引导页 -->
    <PermissionGuide v-if="currentStep === 'permissions'" @next="nextStep" @back="previousStep" @finish="finishGuide" />
    <!-- 完成引导页 -->
    <div v-if="currentStep === 'complete'" class="complete-guide">
      <div class="background-animation">
        <div class="confetti-container">
          <div class="confetti" v-for="n in 50" :key="n" :style="getConfettiStyle(n)"></div>
        </div>
      </div>
      
      <div class="complete-content">
        <div class="success-animation">
          <div class="checkmark">
            <svg viewBox="0 0 52 52">
              <circle class="checkmark-circle" cx="26" cy="26" r="25" fill="none"/>
              <path class="checkmark-check" fill="none" d="m14.1 27.2l7.1 7.2 16.7-16.8"/>
            </svg>
          </div>
          <div class="success-glow"></div>
        </div>
        
        <h1 class="complete-title">引导完成！</h1>
        <p class="complete-subtitle">现在您可以开始使用智慧医疗助手了</p>
        
        <div class="complete-features">
          <div class="feature-summary" v-for="(feature, index) in completeFeatures" :key="index">
            <div class="feature-icon">{{ feature.icon }}</div>
            <span class="feature-text">{{ feature.text }}</span>
          </div>
        </div>
        
        <button class="start-btn" @click="startApp">
          <span class="btn-text">开始使用</span>
          <span class="btn-icon">🚀</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import WelcomeGuide from './WelcomeGuide.vue'
import FeatureGuide from './FeatureGuide.vue'
import PermissionGuide from './PermissionGuide.vue'

const router = useRouter()
const currentStep = ref('welcome')

const steps = ['welcome', 'features', 'permissions', 'complete']

const completeFeatures = [
  { icon: '🎉', text: '欢迎使用智慧医疗助手' },
  { icon: '⚡', text: '快速开始您的健康管理之旅' },
  { icon: '💡', text: '如有问题可随时查看帮助' }
]

const getConfettiStyle = (index: number) => {
  const colors = ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#feca57', '#ff9ff3']
  const color = colors[index % colors.length]
  const left = Math.random() * 100
  const animationDelay = Math.random() * 3
  const animationDuration = 3 + Math.random() * 2
  
  return {
    left: `${left}%`,
    backgroundColor: color,
    animationDelay: `${animationDelay}s`,
    animationDuration: `${animationDuration}s`
  }
}

const nextStep = () => {
  const currentIndex = steps.indexOf(currentStep.value)
  if (currentIndex < steps.length - 1) {
    currentStep.value = steps[currentIndex + 1]
  }
}

const previousStep = () => {
  const currentIndex = steps.indexOf(currentStep.value)
  if (currentIndex > 0) {
    currentStep.value = steps[currentIndex - 1]
  }
}

const skipGuide = () => {
  // localStorage.setItem('guideCompleted', 'true')  // 临时注释，测试用
  router.push('/login')
}

const finishGuide = () => {
  // localStorage.setItem('guideCompleted', 'true')  // 临时注释，测试用
  currentStep.value = 'complete'
}

const startApp = () => {
  router.push('/login')
}

onMounted(() => {
  // 引导容器组件挂载时，直接显示引导流程
  // 不需要检查 guideCompleted 状态，因为用户主动点击了"开始引导"
  currentStep.value = 'welcome'
})
</script>

<style scoped lang="scss">
.guide-container {
  min-height: 100vh;
  position: relative;
}

.complete-guide {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: white;
  position: relative;
  overflow: hidden;
}

.background-animation {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.confetti-container {
  position: relative;
  width: 100%;
  height: 100%;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  border-radius: 2px;
  animation: confetti-fall linear infinite;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-10px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

.complete-content {
  max-width: 450px;
  width: 100%;
  text-align: center;
  position: relative;
  z-index: 1;
  animation: fadeInUp 0.8s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.success-animation {
  margin-bottom: 40px;
  position: relative;
}

.checkmark {
  width: 100px;
  height: 100px;
  margin: 0 auto;
  border-radius: 50%;
  display: block;
  stroke-width: 2;
  stroke: white;
  stroke-miterlimit: 10;
  animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
  position: relative;
  z-index: 2;
}

.success-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
  animation: pulse 2s ease-in-out infinite;
  z-index: 1;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(1.1);
  }
}

.checkmark-circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 2;
  stroke-miterlimit: 10;
  stroke: white;
  fill: none;
  animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark-check {
  transform-origin: 50% 50%;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes stroke {
  100% {
    stroke-dashoffset: 0;
  }
}

@keyframes scale {
  0%, 100% {
    transform: none;
  }
  50% {
    transform: scale3d(1.1, 1.1, 1);
  }
}

@keyframes fill {
  100% {
    box-shadow: inset 0px 0px 0px 30px rgba(255, 255, 255, 0.2);
  }
}

.complete-title {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 12px;
  text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #ffffff, #f0f0f0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.complete-subtitle {
  font-size: 18px;
  opacity: 0.95;
  margin-bottom: 40px;
  font-weight: 300;
  letter-spacing: 0.5px;
}

.complete-features {
  margin-bottom: 50px;
}

.feature-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateX(8px);
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  }
  
  &:nth-child(1) { animation-delay: 0.2s; }
  &:nth-child(2) { animation-delay: 0.4s; }
  &:nth-child(3) { animation-delay: 0.6s; }
  
  animation: slideInRight 0.6s ease-out forwards;
  opacity: 0;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.feature-icon {
  font-size: 24px;
  margin-right: 12px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.feature-text {
  font-size: 16px;
  opacity: 0.9;
  font-weight: 500;
}

.start-btn {
  padding: 18px 40px;
  border: none;
  border-radius: 30px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  color: #667eea;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
  
  &:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.25);
    background: linear-gradient(135deg, #ffffff 0%, #e9ecef 100%);
  }
  
  &:active {
    transform: translateY(-1px);
  }
}

.btn-text {
  transition: transform 0.3s ease;
}

.btn-icon {
  font-size: 20px;
  transition: transform 0.3s ease;
}

.start-btn:hover .btn-icon {
  transform: scale(1.1) rotate(10deg);
}

@media (max-width: 768px) {
  .complete-content {
    padding: 0 20px;
  }
  
  .complete-title {
    font-size: 28px;
  }
  
  .complete-subtitle {
    font-size: 16px;
  }
  
  .feature-summary {
    padding: 14px 16px;
    margin-bottom: 12px;
  }
  
  .feature-text {
    font-size: 15px;
  }
  
  .start-btn {
    padding: 16px 32px;
    font-size: 17px;
  }
  
  .checkmark {
    width: 80px;
    height: 80px;
  }
  
  .success-glow {
    width: 120px;
    height: 120px;
  }
}

@media (max-width: 480px) {
  .complete-title {
    font-size: 24px;
  }
  
  .complete-subtitle {
    font-size: 15px;
  }
  
  .feature-summary {
    padding: 12px 14px;
  }
  
  .feature-text {
    font-size: 14px;
  }
  
  .start-btn {
    padding: 14px 28px;
    font-size: 16px;
  }
  
  .checkmark {
    width: 70px;
    height: 70px;
  }
  
  .success-glow {
    width: 100px;
    height: 100px;
  }
}
</style> 